package org.kitten.core.util;

public class NameUtil {
	public static String tblName2Clazz(String t) {
		StringBuffer sb = new StringBuffer(t.length());
		String[] seg = t.split("_");
		for (int i = 0; i < seg.length; i++) {
			sb.append(upper(seg[i].toLowerCase()));
		}
		return sb.toString();
	}
	public static String columnName2Field(String t) {
		StringBuffer sb = new StringBuffer(t.length());
		String[] seg = t.split("_");
		for (int i = 0; i < seg.length; i++) {
			sb.append(upper(seg[i].toLowerCase()));
		}
		return lower(sb.toString());
	}
	public static String upper(String source) {
		source = StringUtil.nvl(source);
		int length = source.length();
		String str_temp;
		if (length == 0) {
			return "";
		}
		str_temp = (source.charAt(0) + "").toUpperCase();
		return str_temp + (length > 1 ? source.substring(1) : "");
	}

	public static String lower(String source) {
		source = StringUtil.nvl(source);
		int length = source.length();
		String str_temp;
		if (length == 0) {
			return "";
		}
		str_temp = (source.charAt(0) + "").toLowerCase();
		return str_temp + (length > 1 ? source.substring(1) : "");
	}

	public static String pkgName2Path(String pkgName) {
		if (pkgName == null) {
			return null;
		}
		return pkgName.replaceAll("\\.", "/");
	}
	public static void main(String[] args) {
		System.out.println(NameUtil.pkgName2Path("com.abc.dddd"));
	}
}
